package insta.project;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TabHost;

public class AccueilActivity extends TabActivity {
	/** Called when the activity is first created. */
	
	private static final int CREATE_PLAYLIST = 1;
	private static final int DELETE_PLAYLIST = 2;
	private static final int VIEW_PLAYLISTS = 3;
	public static TabHost tabHost;
	private TabHost.TabSpec specSongs;
	private TabHost.TabSpec specPlaylist;
	private TabHost.TabSpec specStreaming;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Resources res = getResources();
		tabHost = getTabHost();
		Intent intent;

		intent = new Intent().setClass(this, SongsGroup.class);
		specSongs = tabHost
				.newTabSpec(res.getString(R.string.onglet1))
				.setIndicator(res.getString(R.string.onglet1),
						res.getDrawable(R.drawable.ic_tab_songs))
				.setContent(intent);
		tabHost.addTab(specSongs);

		// intent = new Intent().setClass(this, NewPlayListActivity.class);
		intent = new Intent().setClass(this, PlaylistsGroup.class);
		specPlaylist = tabHost
				.newTabSpec(res.getString(R.string.onglet2))
				.setIndicator(res.getString(R.string.onglet2),
						res.getDrawable(R.drawable.ic_tab_playlist))
				.setContent(intent);
		tabHost.addTab(specPlaylist);

		intent = new Intent().setClass(this, SongsActivity.class);
		intent.putExtra("playlist_number", -2);
		specStreaming = tabHost
				.newTabSpec(res.getString(R.string.onglet3))
				.setIndicator(res.getString(R.string.onglet3),
						res.getDrawable(R.drawable.ic_tab_podcast))
				.setContent(intent);
		tabHost.addTab(specStreaming);

		tabHost.setCurrentTab(0);
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		int tab = getTabHost().getCurrentTab();
		if (tab == 1) {
			super.onCreateOptionsMenu(menu);
			menu.add(0, CREATE_PLAYLIST, 0, "Create playlist");
			menu.add(0, VIEW_PLAYLISTS, 0, "View playlists");
			menu.add(0, DELETE_PLAYLIST, 0, "Delete playlists");
		}
		return true;

	};

	
	public boolean onOptionsItemSelected(MenuItem item) {

		View view = null;
		Intent intent;
		switch (item.getItemId()) {
		case CREATE_PLAYLIST:
			intent = new Intent().setClass(this, NewPlayListActivity.class);
			view = getLocalActivityManager().startActivity("NewPlaylistActivity",
					intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
			break;
		case DELETE_PLAYLIST:
			intent = new Intent().setClass(this, PlayListActivity.class);
			intent.putExtra("action", "remove");
			view = getLocalActivityManager().startActivity("PlaylistActivity",
					intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
			break;
		case VIEW_PLAYLISTS:
			intent = new Intent().setClass(this, PlayListActivity.class);
			intent.putExtra("action", "view");
			view = getLocalActivityManager().startActivity("PlaylistActivity",
					intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
			break;
		}
		
		if (view != null) PlaylistsGroup.group.replaceView(view);
		return super.onContextItemSelected(item);
	}
}